package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.RoleFun;
import com.hopu.blb_erp.service.RoleFunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class RoleFunController {

    @Autowired
    private RoleFunService roleFunService;

    @ApiOperation("按角色id和权限id查询角色和权限的关系")
    @GetMapping("/role-function")
    public ResponseEntity<String> find(@RequestBody RoleFun roleFun) {
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("添加角色和权限的关系")
    @PostMapping("/role-function")
    public ResponseEntity<String> add(@RequestBody RoleFun roleFun) {
        String add = roleFunService.add(roleFun);
        return ResponseEntity.ok(add);
    }

    @ApiOperation("删除角色和权限的关系")
    @DeleteMapping("/role-function/{roleId}/{funId}")
    public ResponseEntity<String> delete(@PathVariable("roleId")Long roleId,
                                         @PathVariable("funId")Long funId) {
        String remove = roleFunService.remove(new RoleFun(0L,roleId,funId));
        return ResponseEntity.ok(remove);
    }
}
